import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: '',
    Tabs: [],
  },
  getters: {
  },
  mutations: {
    setToken(state, Token){
      state.token = Token
    },
    initStore(state){
      if(localStorage.state){
        this.replaceState(JSON.parse(localStorage.state))
      }
    },
    empty(state){
      state.Tabs=[],
      state.token=''
    },
    setTab(state, tab){
      const index = state.Tabs.findIndex(item => item.path === tab.path);
      if (index === -1) {
        state.Tabs.push(tab);
      }
    },
    removeTab(state, index){
      state.Tabs.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  }
})
